package com.xiaoyu.im.client.proxy.nim;

import androidx.annotation.IntDef;
import androidx.annotation.StringDef;
import android.util.SparseArray;

public class AntiSpamResult {

    @OperatorDef
    public final int operator;
    @OperatorTypeDef
    public final String operatorType;
    public final String destText;

    public AntiSpamResult(@OperatorDef int operator, String destText) {
        this.operator = operator;
        this.operatorType = toOperatorType(operator);
        this.destText = destText;
    }

    public static final int OPERATOR_NOT_HIT = 0;
    public static final int OPERATOR_LOCAL_REPLACE = 1;
    public static final int OPERATOR_FORBIDDEN = 2;
    public static final int OPERATOR_SERVER_FORBIDDEN = 3;

    public static final String OPERATOR_TYPE_NOT_HIT = "not_hit";
    public static final String OPERATOR_TYPE_LOCAL_REPLACE = "local_replace";
    public static final String OPERATOR_TYPE_FORBIDDEN = "local_forbidden";
    public static final String OPERATOR_TYPE_SERVER_FORBIDDEN = "server_forbidden";

    @IntDef({OPERATOR_NOT_HIT, OPERATOR_LOCAL_REPLACE, OPERATOR_FORBIDDEN, OPERATOR_SERVER_FORBIDDEN})
    public @interface OperatorDef {
    }

    @StringDef({OPERATOR_TYPE_NOT_HIT, OPERATOR_TYPE_LOCAL_REPLACE, OPERATOR_TYPE_FORBIDDEN, OPERATOR_TYPE_SERVER_FORBIDDEN})
    public @interface OperatorTypeDef {
    }

    private static final SparseArray<String> MAP = new SparseArray<>();

    static {
        MAP.put(OPERATOR_NOT_HIT, OPERATOR_TYPE_NOT_HIT);
        MAP.put(OPERATOR_LOCAL_REPLACE, OPERATOR_TYPE_LOCAL_REPLACE);
        MAP.put(OPERATOR_FORBIDDEN, OPERATOR_TYPE_FORBIDDEN);
        MAP.put(OPERATOR_SERVER_FORBIDDEN, OPERATOR_TYPE_SERVER_FORBIDDEN);
    }

    @OperatorTypeDef
    public static String toOperatorType(@OperatorDef int operator) {
        String operatorType = MAP.get(operator);
        return operatorType != null ? operatorType : OPERATOR_TYPE_NOT_HIT;
    }

    @Override
    public String toString() {
        return "AntiSpamResult{" +
                "operator=" + operator +
                ", operatorType='" + operatorType + '\'' +
                ", destText='" + destText + '\'' +
                '}';
    }
}
